<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>制定工序物料设计单</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/manufactureCss/b/Process_material_design _sheet.css"/>
    <style type="text/css">

    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">生产管理</a></li>
            <li class="breadcrumb-item"><a href="#">工序物料设计</a></li>
            <li class="breadcrumb-item active" aria-current="page">制定工序物料设计单</li>
        </ol>
    </nav>
</div>
<div style="margin-bottom: 2px">
    <div style="display: inline;margin-left: 86%;">
        <button class="btn btn-primary" id="submit">提交</button>
        <button class="btn btn-primary">返回</button>
    </div>
</div> <!-- 此div改用栅格来做 -->
<div id="designListBox">
    <div style="text-align: center">
        <h3>工序物料设计单</h3>
    </div>
    <div style="padding: 30px">
        <table class="tbl1">
            <tr>
                <td class="col1">工序单编号：</td>
                <td class="col2" id="designId">aaa</td>
<%--                <td class="col1">设计人：</td>--%>
<%--                <td class="col2">--%>
<%--                    <input type="text" class="txt_under_line" id="Designer">--%>
<%--                </td>--%>
            </tr>
            <tr>
                <td class="col1">产品名称：</td>
                <td colspan="1" id="productName">
                    小米笔记本
                </td>
                <td class="col1">产品编号：</td>
                <td colspan="2" id="productId">
                    aaaaaaaaaaaaaaa
                </td>
            </tr>
        </table>
        <input type="hidden" id="id" value=""/>
        <table id="tbl2" class="table table-bordered" style="margin: 15px auto;">
            <thead>
            <tr>
                <th>序号</th><th width="85px">工序名称</th><th width="85px">工序编号</th>
                <th width="380px">描述</th><th width="110px">工时数(小时)</th><th width="150px">工时成本小计(元)</th>
                <th width="120px">物料成本小计</th><th>设计</th>
            </tr>
            </thead>
            <tbody id="template" style="text-align: center;">
                <tr>
                    <td class="ckbox">1</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="num"></td>
                    <td class="num"></td>
                    <td class="num"></td>
                    <td><a href="" class="btn btn-outline-success ">设计</a></td>
                </tr>
            </tbody>

        </table>

        <table class="tbl1">
            <tr>
                <td class="col1">工时总成本：</td>
                <td class="col2" id="costPriceSum">0</td>
                <td class="col1">物料总成本：</td>
                <td class="col2" id="moduleCostPriceSum">0</td>
            </tr>
<%--            <tr>--%>
<%--                <td class="col1">设计要求：</td>--%>
<%--                <td colspan="3" style="padding-top: 5px">--%>
<%--                    <textarea rows="4" cols="100" id="moduleDescribe"></textarea>--%>
<%--                </td>--%>
<%--            </tr>--%>
        </table>
    </div>
</div>
<div class="modal fade" id="AddProductProcessMaterialModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content" style="height: 450px">
            <div class="modal-header" style="height: 8%">
                <h3 class="modal-title" id="staticBackdropLabel">添加物料</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="height: 100%;width: 100%;margin: -1%">
                <iframe id="iframe2" src="" style="width: 100%;height: 99%"></iframe>
            </div>
            <div class="modal-footer" style="height: 15%">
                <button id="btnConcel" class="btn btn-success" data-bs-dismiss="modal">
                    确认<span class="glyphicon glyphicon-remove"></span>
                </button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    $(function (){
        initialDesignSheet();

        $("#AddProductProcessMaterialModal").on("hidden.bs.modal",function (){
            let tr = $("#template tr")
            for (let i = 0; i < tr.length; i++) {
                 let id = tr.eq(i).find("td:eq(0)").attr("id")
                 console.log(id);
                 let data = sessionStorage.getItem(id)!=null?JSON.parse(sessionStorage.getItem(id)):null;
                 if (data!=null){
                     let data2 = data[id];
                     let money = 0;
                     let leg = data2.length;
                     if (leg>0){
                         for (let j = 0; j < leg; j++) {
                             let amount = data2[j].amount;
                             let costPrice = data2[j].costPrice
                             money += amount*costPrice;
                         }
                         tr.eq(i).find("td:eq(6)").text(money);
                         moduleCostPriceSum();
                     }
                 }else {
                     continue;
                 }
            }
        })

        $("#submit").click(function(){
            let designId = $("#designId").text();
            let costPriceSum = $("#costPriceSum").text();
            let moduleCostPriceSum = $("#moduleCostPriceSum").text();
            let data = [];
            data.push({
                "designId":designId,
                "costPriceSum":costPriceSum,
                "moduleCostPriceSum":moduleCostPriceSum,
            })
            let tr = $("#template tr")
            for (let i = 0; i < tr.length; i++) {
                let id = tr.eq(i).find("td:eq(0)").attr("id")
                sessionStorage.getItem(id)!=null?data.push(JSON.parse(sessionStorage.getItem(id))):null;
            }
            sessionStorage.setItem("data",JSON.stringify(data));
            alert("提交成功!请点击确认返回！")
        })
    })
    function moduleCostPriceSum(){
        let tr = $("#template tr")
        let moduleCostPriceSum = 0;
        for (let i = 0; i < tr.length; i++) {
            let money = tr.eq(i).find("td:eq(6)").text()
            console.log(money);
            moduleCostPriceSum += parseFloat(money);
        }
        $("#moduleCostPriceSum").text(moduleCostPriceSum)
    }
    function initialDesignSheet(){
        let id = sessionStorage.getItem("id");
        $.ajax({
            type: "GET",
            url: "/m-design-procedure-module/initialDesignSheet?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data);
                $("#designId").text(data.designId);
                $("#productId").text(data.productId);
                $("#productName").text(data.productName);
                $("#costPriceSum").text(data.costPriceSum);
                $("#id").val(data.id);
                initialTable(id);
            }
        })
    }
    function initialTable(id){
        $.ajax({
            type: "GET",
            url: "/m-design-procedure-details/selectArrByParentId?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data);
                $("#template").empty()

                for (let i = 0; i < data.length; i++) {
                    let moduleSubtotal = 0;
                    data[i].moduleSubtotal === null ? moduleSubtotal = 0 : moduleSubtotal = data[i].moduleSubtotal;
                    let tr = "<tr>" +
                        "<td class='ckbox' id='"+data[i].procedureId+"'>"+(i+1)+"</td>" +
                        "<td>"+data[i].procedureName+"</td>" +
                        "<td>"+data[i].procedureId+"</td>" +
                        "<td>"+data[i].procedureDescribe+"</td>" +
                        "<td class='num'>"+data[i].labourHourAmount+"</td>" +
                        "<td class='num'>"+data[i].subtotal+"</td>" +
                        "<td class='num'>"+moduleSubtotal+"</td>" +
                        '<td><a href="javascript:devise('+'\''+data[i].procedureId+'\''+')" class="btn btn-outline-success">设计</a></td>' +
                        "</tr>";
                    $("#template").append(tr);
                }
            }
        })
    }
    function devise(procedureId){
        sessionStorage.setItem("procedureId",procedureId);
        sessionStorage.setItem("productId",$("#productId").text());
        $("#AddProductProcessMaterialModal").modal("show");
        $("#iframe2").attr("src","/m-design-procedure-module/ProcessMaterialDesignSub");

    }
</script>
</body>
</html>
